﻿using System.Web.UI;

namespace AutoCompleteTextBox
{
    public class AutocompleteYQLDataSource : AutocompleteDataSource
    {
        public string ResultListLocator { get; set; }

        public string ResultTextLocator { get; set; }

        public override string RenderDataSource()
        {
            string queryString = null;

            foreach (Control c in Controls)
            {
                if (c is AutocompleteYQLDataSourceQueryString)
                {
                    queryString += ((AutocompleteYQLDataSourceQueryString)c).GetQueryString();
                }
            }

            var so = GetSettingsObject();
            so.ClientID = ClientID.ToString();
            so.Source = "'" + queryString + "'";
            so.ResultListLocator = ResultListLocator;
            so.ResultTextLocator = ResultTextLocator;

            RegistrarClientScript.ClientScriptManager(Page, ClientID, so.GetString());
            
            return ClientID.ToString();
        }
    }
}
